#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 40;

int n;
int postorder[N], inorder[N];
unordered_map<int, int> l, r, pos; // 存放二叉树的左儿子和右儿子
queue<int> q;
vector<int> res;

void BFS(int root) {
    q.push(root);
    while (q.size()) {
        auto h = q.front();q.pop();
        if (l.count(h)) q.push(l[h]);
        if (r.count(h)) q.push(r[h]);
        res.push_back(h);
    }
}

int build(int il, int ir, int pl, int pr) {
    int root = postorder[pr];
    int k = pos[root];

    if (il < k) l[root] = build(il, k - 1, pl, pl + (k - 1 - il));
    if (ir > k) r[root] = build(k + 1, ir, pl + (k - 1 - il) + 1, pr - 1);
    return root;
}

inline void solution() {
    cin >> n;
    for (int i = 0; i < n; i ++ )
        cin >> postorder[i];
    for (int i = 0; i < n; i ++ ) {
        cin >> inorder[i];
        pos[inorder[i]] = i;
    }

    int root = build(0, n - 1, 0, n - 1);
    BFS(root);

    cout << res[0];
    for (int i = 1; i < res.size(); i ++ ) 
        cout << " " << res[i];
    cout << endl;
    return ;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}